package com.hhf.feiojjudgeservice.codesandbox.impl;

import com.hhf.feiojjudgeservice.codesandbox.CodeSandbox;
import com.hhf.feiojjudgeservice.codesandbox.model.ExecuteCodeRequest;
import com.hhf.feiojjudgeservice.codesandbox.model.ExecuteCodeResponse;

import com.hhf.feiojcommonservice.model.dto.JudgeInfo;
import com.hhf.feiojjudgeservice.model.enums.JudgeInfoMessageEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;

/**
 * @Author hhf
 * @Date 2024/10/27
 * @Description 示例代码沙箱(为了业务的跑通)
 */
@Slf4j
public class ExampleCodeSandbox implements CodeSandbox {
    @Override
    public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {

        List<String> inputList = executeCodeRequest.getInputList();
        String code = executeCodeRequest.getCode();
        String language = executeCodeRequest.getLanguage();

        //实际情况将inputList,code和language传入代码沙箱,获取memory,time,message和outputList
        String result = inputList.toString() + code + language;
        log.info("代码沙箱执行完毕:{}", result);

        //构造响应对象
        List<String> outputList = Arrays.asList("2", "3");

        JudgeInfo judgeInfo = new JudgeInfo();
        judgeInfo.setMemory(100L);
        judgeInfo.setTime(100L);
        judgeInfo.setMessage(JudgeInfoMessageEnum.ACCEPTED.getValue());

        ExecuteCodeResponse response = ExecuteCodeResponse.builder()
                .judgeInfo(judgeInfo)
                .outputList(outputList).build();

        //返回结果
        return response;
    }
}
